package org.vectrics.user.web.struts;


import java.util.List;
import org.vectrics.SystemException;
import org.vectrics.common.pagelist.PageList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.user.*;


/**
 * @author mmoore
 *
 */
public class PersonPageList extends PageList {
	static private transient final Log log =  LogFactory.getLog(PersonPageList.class);
	private PersonSearcher personSearcher = null;
	/**
	 * 
	 */
	public PersonPageList(PersonSearcher personSearcher) {
		super();
		this.personSearcher = personSearcher;
	}
	
	

	public int getTotalElementCount() {
		if (this.getCriteria() == null)
			throw new SystemException("criteria not set before using this pagelist");
		
		int count = this.personSearcher.findPersonCount((PersonSearchCriteria)getCriteria());
		return(count);
	}

	public List getElements(int startIndex, int endIndex) {
		log.debug("getElements() called");
		if (this.getCriteria() == null)
			throw new SystemException("criteria not set before using this pagelist");
		List userIds = null;
		userIds = this.personSearcher.findPersons((PersonSearchCriteria)getCriteria(), 
				startIndex, endIndex);
		if (log.isDebugEnabled()) {
			log.debug("getElements() - list size = " + userIds.size());
		}
		return(userIds);
	}


}
